<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="baseurl" value="${pageContext.request.contextPath}/"></c:set>
<%
	String path = request.getContextPath();
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="${baseurl}CSS/backMange.css">
<!-- 下拉 -->
<link rel="stylesheet" type="text/css"href="${baseurl}common/lowSelect/lib/css/htools.select.skin.css">
<!-- css资源 -->
<link rel="stylesheet" type="text/css" href="${baseurl}easyUI1.4.1/themes/default/easyui.css">
<!-- 图标资源 -->
<link rel="stylesheet" type="text/css" href="${baseurl}easyUI1.4.1/themes/icon.css"> 
<script type="text/javascript" src="${baseurl}easyUI1.4.1/jquery.min.js"></script>
<!-- 下拉 -->
<script type="text/javascript" src="${baseurl}common/lowSelect/lib/js/jquery.htools.select.js"></script>
<!--EasyUI的js包 -->
<script type="text/javascript" src="${baseurl}easyUI1.4.1/jquery.easyui.min.js"></script>
<!-- 本地语言 -->
<script type="text/javascript" src="${baseurl}easyUI1.4.1/locale/easyui-lang-zh_CN.js"></script>


 <script type="text/javascript" src="${baseurl}common/easySelect/jquery.cssforms.js"></script> 
<%@ include file="/WEB-INF/JSP/ajax.jsp"%>
<script type="text/javascript">
//IE不支持console对象，此代码仅为测试使用
///////////////////////////////////////
window.console = window.console || (function () {
var c = {}; c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile  
= c.clear = c.exception = c.trace = c.assert = function () { };  
return c;  
})();  
//////////////////////////////////////
function add(){
	$user_list_companyLFunmber = $("#companyLFunmber_hide_id").val();
	$("#add_companyNumber_input").val($("#companyLFunmber_hide_id").val());
	$("#add_company_input").val($("#companyName_hide_id").val());
	$("#add_companyID_input").val($("#companyId_hide_id").val());
	
	$("#add_window_div").attr("style","width:350px;height:250px");
	$('#add_window_div').window('open');
}
function edit(){

    var thisBean = $('#user_list_table').datagrid('getSelected');
    console.log(thisBean);
    if(thisBean == null || thisBean.length == 0){
        $.messager.alert('提示','单击选择需要修改行!');
        return;
    }else if($('#user_list_table').datagrid('getSelections').length > 1 ){
        $.messager.alert('提示','请选择正确的修改行!');
        return;
	}

	$("#update_company_input").val("");
	$("#update_companyID_input").val("");
	$("#update_dept_input").val("");
	$("#update_deptID_input").val("");


	var thisId = thisBean.id;
	$.ajax({
	      url:'${baseurl}DrivingSys/user/userdata.action',  
	      type: "post",  
	      dataType:"json",
	      //timeout : 10000,
	      data:{"id":thisId}, 
	      success: function(json) {
	    	$("#update_window_div").attr("style","width:350px;height:250;");
	    	$('#update_window_div').window('open');
	      	var user = json.user;
	      	$("#update_id_input").val(user.id);
	      	optionSet("#update_fisPower","否");
	      	//$("#test").attr("selected","selected");
	      	$("#update_name").val(user.name);
	      	$("#update_userName").val(user.userName);
	      	$("#update_company_input").val(user.companyName);
	      	$("#update_companyID_input").val(user.fcompanyid);
	      	$user_list_companyLFunmber = user.companyLongFnumber;
	      	
	      	
	      	$("#update_companyNumber_input").val($user_list_companyLFunmber);
	      	$("#update_dept_input").val(user.deptName);
	      	$("#update_deptID_input").val(user.deptId);
	      	
	      	$("#update_remark").val(user.remark);
	      	$("#update_ftype").val(user.ftype);
	      	$("#update_fisAdmin").val(user.fisAdmin);
	      	
	      }
	  });
}
function optionSet(selectid,option){
	
	$(selectid).find("option:selected").removeAttr("selected");
	$(selectid).find("option[text='"+option+"']").attr("selected","selected");
}

//打开公司搜索框
function opeanCompany(){
	if(!company_search_flag){
		companySearch();
	}
	//清除用户checked项
	$('#company_list_table').datagrid('clearSelections');
	$("#company_window_div").attr("style","width:450px;height:265px;");
	$('#company_window_div').window('open');
}
//打开部门搜索框
function opeanDept(){
	//if(!dept_search_flag){
		deptSearch();
	//}
	//清除用户checked项
	$('#dept_list_table').datagrid('clearSelections');
	$("#dept_window_div").attr("style","width:450px;height:265px;");
	$('#dept_window_div').window('open');
}
var power_roleList_flag = false;
var power_handList_flag = false;
var power_addRole_flag =false;
var power_addRoleList_flag = false;
var power_tree_flag = false;
var power_addPowerList_flag =false;

var company_search_flag = false;//公司
var dept_search_flag = false;//部门
var checkedUserId = '';
var $user_list_companyLFunmber;//公司长编码
//查询所有角色
function findAddRoleList(){
	if(power_addRoleList_flag){
		if(allCheckStr($('#add_roleList_name_id').val())){
			return;
		}
		$("#add_roleList_list_table").datagrid('reload',{
			fisDelete:'0',
			roleName:$("#add_roleList_name_id").val()
		});
	}else{
		//创建DataGrid
	    $("#add_roleList_list_table").datagrid({
	         url:'${baseurl}DrivingSys/role/list.action',  //数据来源 
	         //冻结列
	            columns:[[
	                { field: 'ck', checkbox: true, width: '30' },  //复选框  
	                {field:'roleCode',title:'角色编码',width:70,align:'center'},
	                {field:'roleName',title:'角色名称',width:120,align:'center'},
	                {field:'remark',title:'备注',width:150,align:'center'}
	            ]],
	            fitColumns:false,//自适应宽度，占满,不能和冻结列同时设置成true
	            fit:true,//充满屏幕
	            striped:true,   //斑马线效果
	            idField:'id',    //主键列
	            rownumbers:true,            //显示行号 
	            singleSelect:false,          //是否单选
	            //cache:false,				//关闭缓存
	            method:'post',
	            pagination:true,
	            pageList:[5,10,20,20],//每页行数选择列表
	            pageSize:5, //设置默认初始的每页行数rows
	            pageNumber:1,//设置默认初始的页码page
	            remoteSort:false,    //是否服务器端排序，设成false才可以在页面进行排序
	            //sortName:'fisAdmin', //指定列名可以进行排序
	            multiSort:true ,
	            onLoadSuccess:function(){
	            	$('#add_roleList_list_table').datagrid('clearSelections');
	            	power_addRoleList_flag = true;
	                return false;
	            },queryParams: {
	            	fisDelete:'0'//未被删除的
		        },loadMsg:'请稍候...'
	    });
	}
}

//查询当前用户未拥有角色
function findAddRole(){
	if(power_addRole_flag){
		if(allCheckStr($('#add_role_name_id').val())){
			return;
		}
		$("#add_role_list_table").datagrid('reload',{
			userId:checkedUserId,
			roleName:$("#add_role_name_id").val()
		});
	}else{
		//创建DataGrid
	    $("#add_role_list_table").datagrid({
	         url:'${baseurl}DrivingSys/power/rolelist.action',  //数据来源 
	         //冻结列
	            columns:[[
	                { field: 'ck', checkbox: true, width: '30' },  //复选框  
	                {field:'roleCode',title:'角色编码',width:70,align:'center'},
	                {field:'roleName',title:'角色名称',width:120,align:'center'},
	                {field:'remark',title:'备注',width:150,align:'center'}
	            ]],
	            fitColumns:false,//自适应宽度，占满,不能和冻结列同时设置成true
	            fit:true,//充满屏幕
	            striped:true,   //斑马线效果
	            idField:'id',    //主键列
	            rownumbers:true,            //显示行号 
	            singleSelect:false,          //是否单选
	            //cache:false,				//关闭缓存
	            method:'post',
	            pagination:true,
	            pageList:[5,10,20,20],//每页行数选择列表
	            pageSize:5, //设置默认初始的每页行数rows
	            pageNumber:1,//设置默认初始的页码page
	            remoteSort:false,    //是否服务器端排序，设成false才可以在页面进行排序
	            //sortName:'fisAdmin', //指定列名可以进行排序
	            multiSort:true ,
	            onLoadSuccess:function(){
	            	$('#add_role_list_table').datagrid('clearSelections');
	            	power_addRole_flag = true;
	                return false;
	            },queryParams: {
	            	userId:checkedUserId
		        },loadMsg:'请稍候...'
	    });
	}
	
}
//查询当前用户未拥有权限
function findAddPowerList(){
		if(allCheckStr($('#add_power_name_id').val())||allCheckStr($('#add_power_Pmenu_name_id').val())){
			return;
		}
	
		$('#add_power_list_table').treegrid('resize',{
			width: 200
		});
		$('#add_power_list_table').treegrid('reload',{
				userId:checkedUserId,
				name:$("#add_power_name_id").val(),
				menuName:$("#add_power_Pmenu_name_id").val()
		});
}
//权限树
function findPowerTree(){
	if(power_tree_flag){
		$("#power_list_table").treegrid('reload',{
			userId:checkedUserId
		});
	}else{
		//创建DataGrid
	    $("#power_list_table").treegrid({
	         url:'${baseurl}DrivingSys/power/userPowerTree.action',  //数据来源 
	         //冻结列
	            columns:[[
	                {field:'name',title:'操作名称',width:200,align:'left'},
	                {field:'type',title:'用户类型',width:60
	                	,align:'center',
		                    formatter:function(value,row,index){
		                        if(value=='sys'){return '父菜单'} 
		             		else if(value=='nav'){return '菜单权限'}
		             		else if(value=='power'){return '操作权限'}
		            }},

                    //{field:'creatTime',title:'时间',width:200,align:'left'},

	                {field:'url',title:'操作路径',width:160,align:'center'}
	            ]],
	            fitColumns:false,//自适应宽度，占满,不能和冻结列同时设置成true
	            fit:true,//充满屏幕
	            animate:false,//是否用动画效果
	            striped:true,   //斑马线效果
	            singleSelect:true,          //是否单选
	            idField:'easyID',           //定义标识树节点的键名字段
	            treeField:'name',       //定义树节点的字段
	            collapsible:false,//是否可折叠
	            showFooter:false,//是否使用页脚
	            /* loader:function(param,success,error){
	            	return false;
	            }, */
	            onBeforeExpand:function(node){
	    	    	return ;
	    		},
	    		onDblClick:function(node){
	    			return false;
	    		},
	            onLoadSuccess:function(){
	            	$('#power_list_table').datagrid('clearSelections');
	            	power_tree_flag = true;
	                return false;
	            },queryParams: {
	            	userId:checkedUserId
		        },loadMsg:'请稍候...'
	    });
	}
	
}
//查询角色与特有权限列表
function roleAndPowerList(){
	if(power_roleList_flag){
		$("#roleAndPower_list_table").datagrid('reload',{
			id:checkedUserId
		});
	}else{
		$("#roleAndPower_list_table").datagrid({
	        url:'${baseurl}DrivingSys/power/userRoleAndPowerList.action',  //数据来源 
	        //冻结列
	           columns:[[
					{ field: 'ck', checkbox: true, width: '30' },  //复选框  
				   {field:'type',title:'名称',width:100,align:'left',
						formatter:function(value,row,index){
							if('role'==value){
								return '<span class="tree-icon tree-folder "></span>'+row.name; 
							}else{
								return '<span class="tree-icon tree-file"></span>'+row.name; 
							}
						}
				   },
	               {field:'url',title:'编码',width:130,align:'center'}
	           ]],
	           fitColumns:false,//自适应宽度，占满,不能和冻结列同时设置成true
	           fit:true,//充满屏幕
	           striped:true,   //斑马线效果
	           idField:'id',    //主键列
	           rownumbers:true,            //显示行号 
	           singleSelect:false,          //是否单选
	           //cache:false,				//关闭缓存
	           method:'post',
	           pagination:false,
	           remoteSort:false,    //是否服务器端排序，设成false才可以在页面进行排序
	           //sortName:'fisAdmin', //指定列名可以进行排序
	           multiSort:true ,
	           onLoadSuccess:function(){
	        	   $('#roleAndPower_list_table').datagrid('clearSelections');
	        	   power_roleList_flag = true;
	               return false;
	           },
	            queryParams: {
	            	id:checkedUserId
		        },loadMsg:'请稍候...'
	   });
	}

}
</script>
</head>
<body style=" margin:0px;  overflow:hidden;">
	<table id="user_list_table"toolbar="#tb">
	</table>
	<input value="${companyName }"id="companyName_hide_id"style="display:none"/>
	<input value="${companyId }"id="companyId_hide_id"style="display:none"/>
	<input value="${companyLFunmber }"id="companyLFunmber_hide_id"style="display:none"/>
	<div id="tb"style="background-color: #f5f5f5;">
		<div style="background-color: #fff;border-radius:10px 10px 0 0;padding-top:10px;padding-left:10px">
			<table >
				<tr >
					<td >
						
							<label style="margin:5px 5px 0 10px ;font-size:14px;float:left">姓名</label>
							<input type="text"  placeholder="姓名" id="name_id"
								style="width:60px;height:27px;margin-right:20px;margin-top: 5px;"/>
					</td>
					<td>
						<label style="margin:5px 5px 0 0px ;font-size:14px;float:left">公司</label>
						<input type="text"  placeholder="请输入公司"id="company_id"value=""
							style="width:70px;height:27px;margin-right:20px;margin-top: 5px;"/>
					</td>
					<td>
						<label style="margin:5px 5px 0 0px ;font-size:14px;float:left">部门</label>
						<input type="text"  placeholder="请输入部门"id="dept_id"value=""
							style="width:70px;height:27px;margin-right:20px;margin-top: 5px;"/>
					</td>
					<td width="160px">
						<div style="float:left;margin:5px 5px 0 5px ;font-size:14px">管理员</div>
						<select id="fisadmin_id">
							<option value="no" selected>全部&nbsp;</option>
							<option value="1">&nbsp;&nbsp;是&nbsp;&nbsp;</option>
							<option value="0">&nbsp;&nbsp;否&nbsp;&nbsp;</option>
						</select>
					</td>
					<td width="150px">
						<div style="float:left;margin:5px 5px 0 10px ;font-size:14px">可用</div>
						<select id="fisDelete_id">
							<option value="no" selected>全部&nbsp;</option>
							<option value="0">&nbsp;&nbsp;是&nbsp;&nbsp;</option>
							<option value="1">&nbsp;&nbsp;否&nbsp;&nbsp;</option>
						</select>
					</td>
					<td width="150px">
						<div style="float:left;margin:5px 5px 0 5px ;font-size:14px">授权</div>
						<select id="fispower_id"c>
							<option value="no" selected>全部</option>
							<option value="1">&nbsp;&nbsp;是&nbsp;&nbsp;</option>
							<option value="0">&nbsp;&nbsp;否&nbsp;&nbsp;</option>
						</select>
					</td>
					<td width="180px">
						<div style="float:left;margin:5px 5px 0 5px ;font-size:14px">当前系统</div>
						<select id="fisproject_id">
							<option value="no" selected>全部</option>
							<option value="1">&nbsp;&nbsp;是&nbsp;&nbsp;</option>
							<option value="0">&nbsp;&nbsp;否&nbsp;&nbsp;</option>
						</select>
					</td>
					<td align="right">
						<input type="button"value="立即搜索" onclick="doSearch()"
							style="width:100px;height:32px;outline:none;border:none;background-image: url(<%=path%>/images/myimages/button.jpg) ;background-position:0px -45px;cursor:hand;color: #fff;border-radius:20px;padding:4px 21px"/>
					</td>
				</tr>
				<tr>
				<shiro:hasPermission name="/user/add.action">
					<%--<td align="left">
						<div class="button_cz" onclick="add()">
							<table>
								<tr>
									<td><img src="${baseurl}images/myimages/xz.png"/></td>
									<td><div >新增</div></td>
								</tr>
							</table>
						</div>
					</td>--%>
				</shiro:hasPermission>
				<shiro:hasPermission name="/user/update.action">
					<td>
						<div class="button_cz" onclick="edit()">
							<table>
								<tr>
									<td><img src="${baseurl}images/myimages/xg.png"/></td>
									<td><div >修改</div></td>
								</tr>
							</table>
						</div>
					</td>
				</shiro:hasPermission>
				<shiro:hasPermission name="/user/power.action">
					<td>
						<div class="button_cz" onclick="addPower()">
							<table>
								<tr>
									<td><img src="${baseurl}images/myimages/xg.png"/></td>
									<td><div >授权</div></td>
								</tr>
							</table>
						</div>
					</td>
				</shiro:hasPermission>
				<shiro:hasPermission name="/user/setProject.action">
					<td>
						<div class="button_cz" onclick="setProject('1')">
							<table>
								<tr>
									<td><img src="${baseurl}images/myimages/xg.png"/></td>
									<td><div >开启项目许可</div></td>
								</tr>
							</table>
						</div>
					</td>
					<td>
						<div class="button_cz" onclick="setProject('0')">
							<table>
								<tr>
									<td><img src="${baseurl}images/myimages/xg.png"/></td>
									<td><div >取消项目许可</div></td>
								</tr>
							</table>
						</div>
					</td>
				</shiro:hasPermission>
				<shiro:hasPermission name="/power/userDeleteRoleAndPower.action">
				
					<td>
						<div class="button_cz" onclick="openSetPowerWindow()">
							<table>
								<tr>
									<td><img src="${baseurl}images/myimages/xg.png"/></td>
									<td><div >设置权限</div></td>
								</tr>
							</table>
						</div>
					</td>
				</shiro:hasPermission>
				<shiro:hasPermission name="/power/usersaddroles.action">
					<td>
						<div class="button_cz" onclick="toPLaddRoleList()">
							<table>
								<tr>
									<td><img src="${baseurl}images/myimages/xz.png"/></td>
									<td><div >批量添加角色</div></td>
								</tr>
							</table>
						</div>
					</td>
				</shiro:hasPermission>
				</tr>
			</table>
		</div>
	</div>
	<!-- 隐藏的添加窗口 -->
	<div id="add_window_div" class="easyui-window user_set_windows" title="添加用户" 
			data-options="modal:true,closed:true,iconCls:'icon-save',top:120" style="width:350px;height:250px;display:none">
		<div style="padding:5px 10px 0px 20px">
	    <form id="add_window_form" method="post"style="width:305px;height:190px">
	    	<table >
	    		<tr >
	    			<td width="30%" class="td_r"><b>*</b>姓名:</td>
	        		<td width="70%" class="td_l">
	        			<input type="text" value=""name="name" />
	        		</td>
	    		</tr>
	    		<tr>
	    			<td width="30%" class="td_r"><b>*</b>账户:</td>
	        		<td width="70%" class="td_l">
	        			<input type="text" value=""name="userName" />
	        		</td>
	    		</tr>
	    		<tr>
	    			<td width="30%" class="td_r"><b>*</b>公司:</td>
	        		<td width="70%" class="td_l">
	        			<input type="text" value=""id="add_company_input" onclick="opeanCompany()"/>
	        			<input  style="display:none"id = "add_companyID_input"/>
	        			<input  style="display:none"id = "add_companyNumber_input"/>
	        		</td>
	    		</tr>
	    		<tr>
	    			<td width="30%" class="td_r">部门:</td>
	        		<td width="70%" class="td_l">
	        			<input type="text" value=""id="add_dept_input" onclick="opeanDept()"/>
	        			<input  style="display:none"id = "add_deptID_input"/>
	        		</td>
	    		</tr>
	    		<tr>
	    			<td width="30%" class="td_r">备注:</td>
	    			<td  width="70%" class="td_l">
	    			<textarea type="text"name="remark" style="width:100%;resize:none"></textarea>
	    			</td>
	    		</tr>
	    		<tr>
	    			<td>用户类型:</td>
	    			<td>
	    				<select class="all_select" name="ftype">
	    					<option value="10">系统用户</option>
	    					<option value="20" selected = "selected">职员</option>
	    					<option value="30">客户</option>
	    					<option value="40">供应商</option>
	    					<option value="50">其他类型</option>
	    					<option value="60">认证管理员</option>
	    					<option value="70">审计管理员</option>
						</select>
					</td>
	    		</tr>
		    	<shiro:hasAnyRoles name="admin_role">
		    		<tr>
		    			<td>是否管理员:</td>
		    			<td>
		    				<select class="all_select" name="fisAdmin">
			    				<option value="1">是</option>
		    					<option value="0" selected = "selected">否</option>
							</select>
						</td>
		    		</tr>
	    		</shiro:hasAnyRoles>
	    		<!-- <tr>
	    		<td>提示：</td>
	    		<td>
	    			<b>密码为默认密码</b>
	    		</td>
	    		</tr> -->
	    	</table>
	    </form>
	    <div style="text-align:center;padding:5px">
	    	<a href="javascript:void(0)" class="easyui-linkbutton"style="margin-right:100px;width:70px;height:30px;" onclick="submitForm()">提交</a>
	    	<a href="javascript:void(0)" class="easyui-linkbutton"style="width:70px;height:30px;" onclick="colseForm()">关闭</a>
	    </div>
	    </div>
	</div>
	<!-- 隐藏的修改窗口 -->
	<div id="update_window_div" class="easyui-window user_set_windows" title="修改用户" 
			data-options="modal:true,closed:true,iconCls:'icon-save',top:120" style="width:350px;height:250px;display:none">
		<div style="padding:5px 10px 0px 20px">
	    <form id="update_window_form" method="post"style="width:305px;height:190px">
	    	<table >
	    		<tr>
	    			<td></td><!-- id -->
	    			<td><input id = "update_id_input"style="display:none" value=""/></td>
	    		</tr>
	    		<tr>
	    			<td width="30%" class="td_r"><b>*</b>姓名:</td>
	        		<td width="70%" class="td_l">
	        			<input type="text" value=""id="update_name" />
	        		</td>
	    		</tr>
	    		<tr>
	    			<td width="30%" class="td_r"><b>*</b>账户:</td>
	        		<td width="70%" class="td_l">
	        			<input type="text" value=""id="update_userName" />
	        		</td>
	    		</tr>
	    		<tr>
	    			<td width="30%" class="td_r"><b>*</b>公司:</td>
	        		<td width="70%" class="td_l">
	        			<input type="text" value=""id="update_company_input" onclick="opeanCompany()"/>
	        			<input  style="display:none"id="update_companyID_input"/>
	        			<input  style="display:none"id = "update_companyNumber_input"/>
	        		</td>
	    		</tr>
	    		<tr>
	    			<td width="30%" class="td_r">部门:</td>
	        		<td width="70%" class="td_l">
	        			<input type="text" value=""id="update_dept_input" onclick="opeanDept()"/>
	        			<input  style="display:none"id = "update_deptID_input"/>
	        		</td>
	    		</tr>
	    		<tr>
	    			<td width="30%" class="td_r">备注:</td>
	        		<td width="70%" class="td_l">
	        			<textarea type="text"id="update_remark" style="width:100%;resize:none"></textarea>
	        		</td>
	    		</tr>
	    		<tr>
	    			<td>用户类型:</td>
	    			<td>
	    				<select id="update_ftype" class="all_select">
	        				<option value="10">系统用户</option>
	    					<option value="20">职员</option>
	    					<option value="30">客户</option>
	    					<option value="40">供应商</option>
	    					<option value="50">其他类型</option>
	    					<option value="60">认证管理员</option>
	    					<option value="70">审计管理员</option>
	        			</select>
					</td>
	    		</tr>
		    	<shiro:hasAnyRoles name="admin_role">
		    		<tr>
		    			<td>是否管理员:</td>
		    			<td>
		    				<select class="all_select" id="update_fisAdmin">
			    				<option value="1">是</option>
		    					<option value="0">否</option>
							</select>
						</td>
		    		</tr>
	    		</shiro:hasAnyRoles>
	    		<!-- <tr>
	    		<td>提示：</td>
	    		<td>
	    			<b>密码为默认密码</b>
	    		</td>
	    		</tr> -->
	    	</table>
	    </form>
	    <div style="text-align:center;padding:5px">
	    	<a href="javascript:void(0)" class="easyui-linkbutton"style="margin-right:100px;width:70px;height:30px;" onclick="setUserForm()">提交</a>
	    	<a href="javascript:void(0)" class="easyui-linkbutton"style="width:70px;height:30px;" onclick="javascript:$('#update_window_div').window('close')">关闭</a>
	    </div>
	    </div>
	</div>
	<!-- 选择公司 -->
 	<div id="company_window_div" class="easyui-window user_set_windows" title="选择公司" 
			data-options="modal:true,closed:true,iconCls:'icon-save',top:120" style="width:450px;height:265px;display:none">
		<div style="height:262px;width:442px">
	    	<table id="company_list_table"toolbar="#company_bar">
			</table>
			<div id="company_bar"style="background-color: #f5f5f5;padding:5px 10px">
				<label style="margin:5px 5px 0 10px ;font-size:14px;float:left">公司名称：</label>
				<input type="text"class="easyui-validatebox"  placeholder="请输入公司名称" id="company_name_input"
								style="width:150px;height:27px;margin-right:20px;"/>
				<input type="button"value="立即搜索" onclick="companySearch()"
							style="width:100px;height:32px;outline:none;border:none;background-image: url(<%=path%>/images/myimages/button.jpg) ;background-position:0px -45px;cursor:hand;color: #fff;border-radius:20px;padding:5px 21px"/>
			</div>
	    </div>
	</div> 
	<!-- 选择部门 -->
	<div id="dept_window_div" class="easyui-window user_set_windows" title="选择公司" 
			data-options="modal:true,closed:true,iconCls:'icon-save',top:120" style="width:450px;height:265px;display:none">
		<div style="height:262px;width:442px">
	    	<table id="dept_list_table"toolbar="#dept_bar">
			</table>
			<div id="dept_bar"style="background-color: #f5f5f5;padding:5px 10px">
				<label style="margin:5px 5px 0 10px ;font-size:14px;float:left">部门名称：</label>
				<input type="text"class="easyui-validatebox"  placeholder="请输入部门名称" id="dept_name_input"
								style="width:150px;height:27px;margin-right:20px;"/>
				<input type="button"value="立即搜索" onclick="deptSearch()"
							style="width:100px;height:32px;outline:none;border:none;background-image: url(<%=path%>/images/myimages/button.jpg) ;background-position:0px -45px;cursor:hand;color: #fff;border-radius:20px;padding:5px 21px"/>
			</div>
	    </div>
	</div> 
	<div id="set_power_window_div" class="easyui-window user_set_windows" title="权限设置" 
			data-options="modal:true,closed:true,iconCls:'icon-save',top:50" style="width:820px;height:500px;display:none">
			
				<div class="easyui-layout" data-options="fit:true">
					<!-- 该用户特有权限及角色部分 -->
					<div data-options="region:'west',split:true" style="width:350px;">
						<table id="roleAndPower_list_table"toolbar="#role_tb">
						</table>
						<div id="role_tb">
							<div style="background-color: #fff;border-radius:10px 10px 0 0;padding-top:10px;">
								<table width="100%">
									<tr >
										<td align="left">
										<shiro:hasPermission name="/power/useraddrole.action">
										
											<div class="button_cz" onclick="toaddRoleList()">
												<table>
													<tr>
														<td><img src="${baseurl}images/myimages/xz.png"/></td>
														<td><div >添加角色</div></td>
													</tr>
												</table>
											</div>
										</shiro:hasPermission>
										</td>
										<td>
										<shiro:hasPermission name="/power/userDeleteRoleAndPower.action">
											<div class="button_cz" onclick="DeleteSave()">
												<table>
													<tr>
														<td><img src="${baseurl}images/myimages/sc.png"/></td>
														<td><div >移除</div></td>
													</tr>
												</table>
											</div>
										</shiro:hasPermission>
										</td>
									</tr>
									<tr >
									
										<td align="left">
										<shiro:hasPermission name="/power/userAddPower.action">
											<div class="button_cz" onclick="addPowerList()">
												<table>
													<tr>
														<td><img src="${baseurl}images/myimages/xz.png"/></td>
														<td><div >添加权限</div></td>
													</tr>
												</table>
											</div>
										</shiro:hasPermission>
										</td>
										<td>
										</td>
									</tr>
								</table>
								
							</div>
						</div>
					</div>
					<!-- 该用户权限树部分 -->
					<div data-options="region:'east'" style="width:450px;padding:10px">
						<table id="power_list_table">
						</table>
					</div>
				</div>
	</div>
	<!-- 添加角色查询 -->
	<div id="add_Role_window_div" class="easyui-window user_set_windows" title="角色设置" 
			data-options="modal:true,closed:true,iconCls:'icon-save',top:120" 
			style="width:400px;height:300px;display:none">
			<table id="add_role_list_table" toolbar="#add_role_inputs_id">
			</table>
			<div id="add_role_inputs_id"style="background-color: #f5f5f5;">
				<div style="background-color: #fff;border-radius:10px 10px 0 0;padding-top:10px;">
					<table width="100%">
						<tr >
							<td width="180px">
									<label style="margin:5px 5px 0 10px ;font-size:14px;float:left">角色名称</label>
									<input type="text"  placeholder="输入角色" id="add_role_name_id"
										style="width:60px;height:27px;margin-right:20px;"/>
							</td>
							<td width="70px">
								<a href="#" class="easyui-linkbutton" iconCls="icon-search"onclick="findAddRole()">搜索</a>
							</td>
							<td><input type="button"value="确定" onclick="SaveRole()"
									style="width:100px;height:32px;outline:none;border:none;background-image: url(<%=path%>/images/myimages/button.jpg) ;background-position:0px -45px;cursor:hand;color: #fff;border-radius:20px;padding:4px 21px"/>
							</td>
						</tr>
					</table>
					
				</div>
		    </div>
	</div>
	<!-- 批量添加角色 -->
	<div id="add_RoleList_window_div" class="easyui-window user_set_windows" title="角色设置" 
			data-options="modal:true,closed:true,iconCls:'icon-save',top:120" 
			style="width:400px;height:300px;display:none">
			<table id="add_roleList_list_table" toolbar="#add_roleList_inputs_id">
			</table>
			<div id="add_roleList_inputs_id"style="background-color: #f5f5f5;">
				<div style="background-color: #fff;border-radius:10px 10px 0 0;padding-top:10px;">
					<table width="100%">
						<tr >
							<td width="180px">
									<label style="margin:5px 5px 0 10px ;font-size:14px;float:left">角色名称</label>
									<input type="text"  placeholder="输入角色" id="add_roleList_name_id"
										style="width:60px;height:27px;margin-right:20px;"/>
							</td>
							<td width="70px">
								<a href="#" class="easyui-linkbutton" iconCls="icon-search"onclick="findAddRoleList()">搜索</a>
							</td>
							<td>
								<input type="button"value="确定" onclick="SaveRoleList()"
									style="cursor:hand;background-color: #54a0ff;color: #fff;border-radius:20px;padding:5px 10px"/>
							</td>
						</tr>
					</table>
					
				</div>
		    </div>
	</div>
	
	<div id="add_Power_window_div" class="easyui-window user_set_windows" title="特有权限设置" 
			data-options="modal:true,closed:true,iconCls:'icon-save',top:120" 
			style="width:540px;height:300px;display:none">
			<table id="add_power_list_table" toolbar="#add_power_inputs_id">
			</table>
			<div id="add_power_inputs_id"style="background-color: #f5f5f5;">
				<div style="background-color: #fff;border-radius:10px 10px 0 0;padding-top:10px;">
					<table width="95%">
						<tr >
							<td width="180px">
									<label style="margin:5px 5px 0 10px ;font-size:14px;float:left">权限名称</label>
									<input type="text"  placeholder="输入权限" id="add_power_name_id"
										style="width:60px;height:27px;margin-right:20px;"/>
							</td>
							<td width="180px">
									<label style="margin:5px 5px 0 10px ;font-size:14px;float:left">父菜单名称</label>
									<input type="text"  placeholder="输入父菜单" id="add_power_Pmenu_name_id"
										style="width:60px;height:27px;margin-right:20px;"/>
							</td>
							<td width="70px">
								<a href="#" class="easyui-linkbutton" iconCls="icon-search"onclick="findAddPowerList()">搜索</a>
							</td>
							<td>
								<input type="button"value="确定" onclick="SaveAddPower()"
									style="cursor:hand;background-color: #54a0ff;color: #fff;border-radius:20px;padding:5px 10px"/>
							</td>
						</tr>
					</table>
					
				</div>
		    </div>
	</div>

</body>

<script type="text/javascript">
var $searchAdminSelect = $("#fisadmin_id");
var $searchDeleteSelect = $("#fisDelete_id");
var $searchPowerSelect = $("#fispower_id");
var $searchProjectSelect = $("#fisproject_id");

/**
 * 初始化插件
 */
$searchAdminSelect.goSelectInput({ height: 30, width: 90});
$searchDeleteSelect.goSelectInput({ height: 30, width: 90});
$searchPowerSelect.goSelectInput({ height: 30, width: 90});
$searchProjectSelect.goSelectInput({ height: 30, width: 90});
//修改
function setUserForm(){
	var id = $("#update_id_input").val();
	var name = $("#update_name").val();
	if(name == "" || name == null){
		$.messager.alert('提示','姓名必填!');
		return true;
	}
	var deptID = $("#update_deptID_input").val();
	var userName = $("#update_userName").val();
	if(name == "" || name == null){
		$.messager.alert('提示','账户必填!');
		return true;
	}
	var remark = $("#update_remark").val();
	var company = $("#update_companyID_input").val();
	if(company == "" || company == null){
		$.messager.alert('提示','请选择公司!');
		return true;
	}
	var ftype = $("#update_ftype").val();
	var fisAdmin = $("#update_fisAdmin").val();
	if (fisAdmin == undefined||fisAdmin == 'undefined'){
		fisAdmin = "";
	}
	$.ajax({
	      url:'${baseurl}DrivingSys/user/update.action',  
	      type: "post",  
	      dataType:"json",
	      //timeout : 10000,
		    data:{"name":name,"id":id*1,
		    	  "userName":userName,"ftype":ftype*1,
		    	  "remark":remark,"deptId":deptID,"fcompanyid":company,"fisAdmin":fisAdmin*1}, 
	      success: function(json) {
	          console.log(json);
	      	$.messager.progress('close');
	      	if(json.error)
	      	{
                $.messager.alert('提示',json.error);
                return;
	      	}else if(json.success != 'success'){
                $.messager.alert('提示',json.success);
                return;
            }

	      	$('#add_window_div').window('close');
	      	$.messager.show({
					title:'提示',
					msg:'修改成功!',
					timeout:3000,
					showType:'slide'
			});
	      	$('#update_window_div').window('close');
	      	doSearch();
	      }
	  });
}
$(function(){
    //创建DataGrid
    $("#user_list_table").datagrid({
         url:'${baseurl}DrivingSys/user/list.action',  //数据来源 
         //冻结列
            columns:[[
                { field: 'ck', checkbox: true, width: '30' },  //复选框  
                {field:'userName',title:'账户',width:35,align:'center'},
                {field:'name',title:'姓名',width:35,align:'center'},
                {field:'deptName',title:'部门',width:120,align:'center'},
                {field:'companyName',title:'公司',width:120,align:'center'},
                {field:'fisproject',title:'驾校用户',width:30
                	,align:'center',
		                    formatter:function(value,row,index){
		                        if(value != null){return '是'}
		             			else{return '否'}                        
		            }
                },
                {field:'fisDelete',title:'可用',width:30
                	,align:'center',
		                    formatter:function(value,row,index){
		                        if(value=='0'){return '是'}  
		             else if(value=='1'){return '否'}                        
		            }
                },
                {field:'fisPower',title:'已授权',width:30
                	,align:'center',
		                    formatter:function(value,row,index){
		                        if(value=='1'){return '是'}  
		             else if(value=='0'){return '否'}                       
		            }
                },
                {field:'fisAdmin',title:'管理员',width:30
	                	,align:'center',
	                    formatter:function(value,row,index){
	                        if(value=='0'){return '否'}  
	             else if(value=='1'){return '是'}                        
	            }},
                {field:'ftype',title:'用户类型',width:50
                	,align:'center',
	                    formatter:function(value,row,index){
	                        if(value=='10'){return ' 系统用户'}  
	             		else if(value=='20'){return '职员'}
	             		else if(value=='30'){return '客户'}
	             		else if(value=='40'){return '供应商'}
	             		else if(value=='50'){return '其他用户'}
	             		else if(value=='60'){return '认证管理员'}
	             		else if(value=='70'){return '审计管理员'}
	            }},
	            {field:'creatId',title:'创建人',width:30,align:'center'},
	            {field:'creatTime',title:'创建时间',width:75,align:'center'},
	            {field:'updateId',title:'修改人',width:30,align:'center'},
	            {field:'updateTime',title:'修改时间',width:75,align:'center'},
                {field:'remark',title:'备注',width:70,align:'center'}
            ]],
            fitColumns:true,//自适应宽度，占满,不能和冻结列同时设置成true
            fit:true,//充满屏幕
            striped:true,   //斑马线效果
            idField:'id',    //主键列
            rownumbers:true,            //显示行号 
            singleSelect:false,          //是否单选
            //cache:false,				//关闭缓存
            method:'post',
            pagination:true,
            pageList:[10,20,50,100],//每页行数选择列表
            pageSize:20, //设置默认初始的每页行数rows
            pageNumber:1,//设置默认初始的页码page
            remoteSort:false,    //是否服务器端排序，设成false才可以在页面进行排序
            //sortName:'fisAdmin', //指定列名可以进行排序
            multiSort:true ,
            onLoadSuccess:function(){
            	$('#user_list_table').datagrid('clearSelections');
            },loadMsg:'请稍候...'

    });
    
    $("#add_power_list_table").treegrid({
    	url:'${baseurl}DrivingSys/power/powerlist.action',
    	method:'post',          //请求方式
        idField:'easyID',           //定义标识树节点的键名字段
        treeField:'name',       //定义树节点的字段
        fit:true,               //网格自动撑满
        fitColumns:true,        //设置为 true，则会自动扩大或缩小列的尺寸以适应网格的宽度并且防止水平滚动。
        animate:true,//是否用动画效果
        striped:true,   //斑马线效果
        singleSelect:false,          //是否单选
        width:500,
        collapsible:false,//是否可折叠
        showFooter:false,//是否使用页脚
        columns:[[
      			 {field: 'ck', checkbox:true, width: 30 },  //复选框
                 {field:'name',title:'名称',width:100,
      					formatter:function(value,row,index){
      	                    if(row.fisDelete == 1){
      	                    	value = '<span style="text-decoration:line-through;color:red">'+row.name+'</span>';
      	                    	return value;
      	                    }
      	         			else{
      	         				value = '<span >'+row.name+'</span>';
      	         				return value;
      	         			}                        
      	        		}
                  },
                  {field:'handleUrl',title:'操作路径',width:170,align:'left'}
              ]],
              onBeforeExpand:function(node){
      	    		return;
	      	  },
	      	  onDblClick:function(node){
	      	  },
	      	  onLoadSuccess:function(){
	      			$('#add_power_list_table').datagrid('clearSelections');
	      	  }
    });
});
function allCheckStr(str){
	var patrn=/[!#@$%^&*()_+<>?:"{},\/;'[\]]/;
	if(patrn.test(str)){
		$.messager.alert('提示','请不要使用非中文符号!');
		return true;     
	}
}
//用户查询
function doSearch(){
	if(allCheckStr($('#name_id').val())||allCheckStr($('#company_id').val())||allCheckStr($('#dept_id').val())){
		return;
	}
	//保留页码查询
	$('#user_list_table').datagrid('reload',{
		name: $('#name_id').val(),
		dept: $('#dept_id').val(),
		company: $('#company_id').val(),
		fisPower: $searchPowerSelect.val(),
		fisAdmin:$searchAdminSelect.val(),
		fisProjecjt:$searchProjectSelect.val(),
		fisDelete:$searchDeleteSelect.val()
	});
}
//公司查询
function companySearch(){
	
	if(company_search_flag){
		var patrn=/[!#@$%^&*()_+<>?:"{},\/;'[\]]/;
		if(patrn.test($('#company_name_input').val())){
			$.messager.alert('提示','请不要使用非中文符号!');
			return true;     
		}
		//保留页码查询
		$('#company_list_table').datagrid('reload',{
			company: $('#company_name_input').val()
		});
	}else{
		$("#company_list_table").datagrid({
	        url:'${baseurl}DrivingSys/common/company.action',  //数据来源 
	        //冻结列
	           columns:[[
	               { field: 'ck', checkbox: true, width: '30' },  //复选框  
	               {field:'companyName',title:'公司名称',width:360,align:'center'}
	           ]],
	           fitColumns:false,//自适应宽度，占满,不能和冻结列同时设置成true
	           fit:true,//充满屏幕
	           striped:true,   //斑马线效果
	           rownumbers:true,            //显示行号 
	           idField:'fid',    //主键列
	           singleSelect:true,          //是否单选
	           cache:true,				//关闭缓存
	           method:'post',
	           pagination:true,
	           pageList:[10,20,50,100],//每页行数选择列表
	           pageSize:20, //设置默认初始的每页行数rows
	           pageNumber:1,//设置默认初始的页码page
	           multiSort:true,
	           onClickRow : function(index, row){
	  				   var selRow = $('#company_list_table').datagrid('getSelections')[0];
	  	        	   $("#add_company_input").val(selRow.companyName);
	  	        	   $("#add_companyID_input").val(selRow.fid);
	  	        	   
	  	        	   $("#add_dept_input").val("");
	  	        	   $("#add_deptID_input").val("");
	  	        	   //公司长编码
	  	        	   $user_list_companyLFunmber = selRow.flongnumber;
	  	        	   $("#add_companyNumber_input").val($user_list_companyLFunmber);
	  	        	   
	  	        	   $("#update_company_input").val(selRow.companyName);
		        	   $("#update_companyID_input").val(selRow.fid);
	  	        	   
		        	   $("#update_dept_input").val("");
		        	   $("#update_deptID_input").val("");
		        	   
	  	        	   $('#company_window_div').window('close');
	   		   },
	        	onLoadSuccess:function(){
	        		 $('#company_list_table').datagrid('clearSelections');
	        		 company_search_flag = true;
	        	},loadMsg:'请稍候...'
	   
	   });
	}
	
}
//部门查询
function deptSearch(){
	console.log($user_list_companyLFunmber)
	if(dept_search_flag){
		var patrn=/[!#@$%^&*()_+<>?:"{},\/;'[\]]/;
		if(patrn.test($('#dept_name_input').val())){
			$.messager.alert('提示','请不要使用非中文符号!');
			return true;     
		}
		//保留页码查询
		$('#dept_list_table').datagrid('reload',{
			dept: $('#dept_name_input').val(),
			companyLongFnumber:$user_list_companyLFunmber
		});
	}else{
		$("#dept_list_table").datagrid({
	        url:'${baseurl}DrivingSys/common/dept.action',  //数据来源 
	        //冻结列
	           columns:[[
	               { field: 'ck', checkbox: true, width: '30' },  //复选框  
	               {field:'fnameL2',title:'部门名称',width:360,align:'center'}
	           ]],
	           fitColumns:false,//自适应宽度，占满,不能和冻结列同时设置成true
	           fit:true,//充满屏幕
	           striped:true,   //斑马线效果
	           rownumbers:true,            //显示行号 
	           idField:'fid',    //主键列
	           singleSelect:true,          //是否单选
	           cache:true,				//关闭缓存
	           method:'post',
	           pagination:true,
	           pageList:[10,20,50,100],//每页行数选择列表
	           pageSize:20, //设置默认初始的每页行数rows
	           pageNumber:1,//设置默认初始的页码page
	           multiSort:true,
	           queryParams: {
	        	   companyLongFnumber:$user_list_companyLFunmber
		       },
	           onClickRow : function(index, row){
	               var selRow = $('#dept_list_table').datagrid('getSelections')[0];
	        	   $("#add_dept_input").val(selRow.fnameL2);
	        	   $("#add_deptID_input").val(selRow.fid);

	        	   $("#update_dept_input").val(selRow.fnameL2);
	        	   $("#update_deptID_input").val(selRow.fid);

	        	   $('#dept_window_div').window('close');
	   		   },
	        	onLoadSuccess:function(){
	        		 $('#dept_list_table').datagrid('clearSelections');
	        		 dept_search_flag = true;
	        	},loadMsg:'请稍候...'
	   
	   });
	}
}
//提交并验证表单
function submitForm(){
	var name = $("[name='name']").val();
	if(name == "" || name == null){
		$.messager.alert('提示','姓名必填!');
		return true;
	}
	var userName = $("[name='userName']").val();
	if(name == "" || name == null){
		$.messager.alert('提示','账户必填!');
		return true;
	}
	var remark = $("[name='remark']").val();
	var company = $("#add_companyID_input").val();
	if(company == "" || company == null){
		$.messager.alert('提示','请选择公司!');
		return true;
	}
	var deptID = $("#add_deptID_input").val();
	var patrn=/[!#@$%^&*()_+<>?:"{},\;'[\]]/;
	
	var ftype = $("[name='ftype']").val();
	var fisAdmin = $("[name='fisAdmin']");
	if(fisAdmin.length == 0){
		fisAdmin = 0;
	}else{
		fisAdmin = $("[name='fisAdmin']").val();
	}
	if(patrn.test(userName)||patrn.test(name)||patrn.test(remark)||patrn.test(deptID)){
		$.messager.alert('提示','请不要使用非中文符号!');
		return true;     
	}
	$.ajax({
      url:'${baseurl}DrivingSys/user/add.action',  
      type: "post",  
      dataType:"json",
      //timeout : 10000,
	    data:{"name":name,"fcompanyid":company,
	    	  "userName":userName,"deptId":deptID,"ftype":ftype*1,
	    	  "remark":remark,"fisAdmin":fisAdmin*1}, 
      success: function(json) {
      	$.messager.progress('close');
      	$('#add_window_div').window('close');
      	$.messager.show({
				title:'提示',
				msg:'添加成功!',
				timeout:3000,
				showType:'slide'
			});
      	doSearch();
      }
  });
}
//关闭 添加表单窗口
function colseForm(){
	$("[name='name']").val("");
	$("[name='userName']").val("");
	$("[name='remark']").val("");
	$('#add_window_div').window('close');
}
//授权
function addPower(){
	var selRow = $('#user_list_table').datagrid('getSelections') ;
	if (selRow.length==0) {
      $.messager.alert("提示", "请选择要操作的行！", "info");  
      return;  
    }
	var ids="";  
  //批量获取选中行的评估模板ID  
  for (i = 0; i < selRow.length;i++) {
  	if(selRow[i].fisPower == '1'){
  		continue;
  	}
      if (ids =="") {  
      	ids = selRow[i].id+"!!!"+selRow[i].userName;  
      } else {
      	ids = selRow[i].id +"!!!"+selRow[i].userName+"," + ids;  
      }      
  }  
  if(ids == ""){
  	$.messager.alert("提示", "选中的未授权用户必须大于一！", "info"); 
  	return;
  }
	$.messager.confirm('提示', '是否授权选中用户?', function (r) {
		  
      if (!r) {
           return;  
      }
		
		$.ajax({
	        url:'${baseurl}DrivingSys/user/power.action',  
	        type: "post",  
	        dataType:"json",
	        //timeout : 10000,
		    data:{"ids":ids}, 
	        success: function(json) {
	        	$.messager.progress('close');
	        	$.messager.show({
					title:'提示',
					msg:'授权成功!',
					timeout:3000,
					showType:'slide'
				});
	        	doSearch();
	        }
	    })
	})
}

//批量设置为当前项目许可用户
function setProject(isP){
	var selRow = $('#user_list_table').datagrid('getSelections') ;
	if (selRow.length==0) {
      $.messager.alert("提示", "请选择要操作的行！", "info");  
      return;  
    }
	var ids="";  
	  //批量获取选中行的评估模板ID  
	  for (i = 0; i < selRow.length;i++) { 
	  	if(isP == '0'&& selRow[i].fisproject == null){
	  		continue;
	  	}
	  	if(isP == '1'&& selRow[i].fisproject != null){
	  		continue;
	  	}
	      if (ids =="") {  
	      	ids = selRow[i].id;  
	      } else {
	      	ids = selRow[i].id +"," + ids;  
	      }      
	  }  
	  if(ids == ""){
	  	$.messager.alert("提示", "选中的可操作用户必须大于一人！", "info"); 
	  	return;
	  }
	  var url = '${baseurl}DrivingSys/user/setProject.action';
	  var message = '是否设置当前项目与用户关联?';
	  if(isP == '0'){
	  	message = '是否取消当前项目与用户关联?';
	  }
	$.messager.confirm('提示', '是否设置当前项目与用户关联?', function (r) {
		  
      if (!r) {
           return;  
      }
      $.ajax({
	        url:'${baseurl}DrivingSys/user/setProject.action',  
	        type: "post",  
	        dataType:"json",
	        //timeout : 10000,
		    data:{"ids":ids,"flag":isP}, 
	        success: function(json) {
	        	$.messager.progress('close');
	        	if(json.success == undefined || json.success == 'undefined'){
		        	$.messager.alert('提示','操作失败，请刷新页面重试!','warning');
	        	}else{
		        	$.messager.show({
						title:'提示',
						msg:'设置成功!',
						timeout:3000,
						showType:'slide'
					});
		        	doSearch();
	        	}
	        }
	    })
	});    
}
//打开选中用户的 权限修改窗口
function openSetPowerWindow(){
	//用户
	var thisBean = $('#user_list_table').datagrid('getSelections');
	if(thisBean.length!=1){
		$.messager.alert("提示", "请选择正确的行数！", "info");  
	    return;  
	}
	checkedUserId = thisBean[0].id;
	roleAndPowerList();
	findPowerTree();
	//打开添加窗口
	$("#set_power_window_div").attr("style","width:800px;height:450px;");
	$('#set_power_window_div').window('open');
}

//////////////////////////////小窗口设置   特有权限 /////////////////////////////////
function addPowerList(){
	//用户ID
	$("#add_power_name_id").val("");
	$("#add_power_Pmenu_name_id").val("");
	findAddPowerList();
	//打开添加窗口
	$("#add_Power_window_div").attr("style","width:540px;height:300px;");
	$('#add_Power_window_div').window('open');
}
//保存特有权限
function SaveAddPower(){
	//用户ID
	var thisBean = $('#user_list_table').datagrid('getSelections');
	if(thisBean.length<1){
		$.messager.alert("提示", "请选择正确的行数！", "info");  
	    return;  
	}
	var obj = thisBean[0];
	var rows = $('#add_power_list_table').datagrid('getSelections');
	if(rows.length<1){
		$.messager.alert("提示", "请至少选择一行！", "info");  
	    return;  
	}
	var names = "";
    var ids="";  
	 //批量获取选中行的模板ID  
    for (i = 0; i < rows.length;i++) {
    	  //如果是菜单跳过
    	  if( rows[i].easyID.indexOf('m') >= 0){
    		continue;
		  }
	      if (ids =="") {
	      	  ids = rows[i].id;  
	      	  names = rows[i].name;  
	      } else {
	      	  ids = rows[i].id +"," + ids;
	      	  names = rows[i].name +"," + names;
	      }
	      
    }
    if(ids == ""){
	  	$.messager.alert("提示", "没有可操作的行！", "info"); 
	  	return;
	}
    $.messager.confirm('提示', '是否为<b>'+obj.name+'</b>添加<b>'+names+'</b>?', function (r) {
	      if (!r) {
	           return;  
	      }
	      $.ajax({
		      url:'${baseurl}DrivingSys/power/userAddPower.action',  
		      type: "post",  
		      dataType:"json",
		      data:{"ids":ids,"userId":checkedUserId}, 
		      success: function(json) {
		    	  if(json.success <=0 ){
			        	$.messager.alert('提示',json.error,'warning');
		          }else{
			        	$.messager.show({
							title:'提示',
							msg:'添加成功!',
							timeout:3000,
							showType:'slide'
						});
			        	//findAddPowerList();
			        	roleAndPowerList();
			        	findPowerTree();
			        	$('#add_Power_window_div').window('close');
		          }
		      }
		  });
		  
	     // roleadd
		  
	}); 
}

//////////////////////////////小窗口设置   角色 /////////////////////////////////
//添加角色
function toaddRoleList(){
	//用户ID
	var thisBean = $('#user_list_table').datagrid('getSelections');
	if(thisBean.length<1){
		$.messager.alert("提示", "请选择正确的行数！", "info");  
	    return;  
	}
	var obj = thisBean[0];
	checkedUserId = obj.id;
	$("#add_role_name_id").val("");
	findAddRole();
	//打开添加窗口
	$("#add_Role_window_div").attr("style","width:700px;height:350px;");
	$('#add_Role_window_div').window('open');
}
//批量添加角色
function toPLaddRoleList(){
	//用户ID
	var thisBean = $('#user_list_table').datagrid('getSelections');
	if(thisBean.length<1){
		$.messager.alert("提示", "请选择正确的行数！", "info");  
	    return;  
	}
	var obj = thisBean[0];
	checkedUserId = obj.id;
	$("#add_roleList_name_id").val("");
	findAddRoleList();
	//打开添加窗口
	$("#add_RoleList_window_div").attr("style","width:700px;height:350px;");
	$('#add_RoleList_window_div').window('open');
}
function DeleteSave(){
	//用户ID
	var thisBean = $('#user_list_table').datagrid('getSelections');
	if(thisBean.length<1){
		$.messager.alert("提示", "请选择正确的行数！", "info");  
	    return;  
	}
	var obj = thisBean[0];
	var rows = $('#roleAndPower_list_table').datagrid('getSelections');
	if(rows.length<1){
		$.messager.alert("提示", "请至少选择一行！", "info");  
	    return;  
	}
	var names = "";
    var ids="";  
	 //批量获取选中行的模板ID  
    for (i = 0; i < rows.length;i++) {
	      if (ids =="") {
	      	  ids = rows[i].id;  
	      	  names = rows[i].name;  
	      } else {
	      	  ids = rows[i].id +"," + ids;
	      	  names = rows[i].name +"," + names;
	      }
	      
    }
    $.messager.confirm('提示', '是否将<b>'+obj.name+'</b>的<b>'+names+'</b>移除?', function (r) {
	      if (!r) {
	           return;  
	      }
	      $.ajax({
		      url:'${baseurl}DrivingSys/power/userDeleteRoleAndPower.action',  
		      type: "post",  
		      dataType:"json",
		      data:{"ids":ids,"userId":checkedUserId}, 
		      success: function(json) {
		    	  if(json.success <=0 ){
			        	$.messager.alert('提示',json.error,'warning');
		          }else{
			        	$.messager.show({
							title:'提示',
							msg:'移除成功!',
							timeout:3000,
							showType:'slide'
						});
			        	roleAndPowerList();
			        	findPowerTree();
		          }
		      }
		  });
		  
	     // roleadd
		  
	}); 
}
function SaveRole(){
	//用户ID
	var thisBean = $('#user_list_table').datagrid('getSelections');
	if(thisBean.length<1){
		$.messager.alert("提示", "请选择正确的行数！", "info");  
	    return;  
	}
	var obj = thisBean[0];
	var rows = $('#add_role_list_table').datagrid('getSelections');
	if(rows.length<1){
		$.messager.alert("提示", "请至少选择一行！", "info");  
	    return;  
	}
	var names = "";
    var ids="";  
	 //批量获取选中行的模板ID  
    for (i = 0; i < rows.length;i++) {
	      if (ids =="") {
	      	  ids = rows[i].id;  
	      	  names = rows[i].roleName;  
	      } else {
	      	  ids = rows[i].id +"," + ids;
	      	  names = rows[i].roleName +"," + names;
	      }      
	      
    }
    $.messager.confirm('提示', '是否为<b>'+obj.name+'</b>添加<b>'+names+'</b>?', function (r) {
	      if (!r) {
	           return;  
	      }
	      $.ajax({
		      url:'${baseurl}DrivingSys/power/useraddrole.action',  
		      type: "post",  
		      dataType:"json",
		      data:{"ids":ids,"userId":checkedUserId}, 
		      success: function(json) {
		    	  if(json.success <=0 ){
			        	$.messager.alert('提示',json.error,'warning');
		          }else{
			        	$.messager.show({
							title:'提示',
							msg:'添加成功!',
							timeout:3000,
							showType:'slide'
						});
			        	//findAddRole();
			        	roleAndPowerList();
			        	findPowerTree();
			        	$('#add_Role_window_div').window('close');
		          }
		      }
		  });
		  
	     // roleadd
		  
	}); 
}
function SaveRoleList(){
	var thisBean = $('#user_list_table').datagrid('getSelections');
	if(thisBean.length<1){
		$.messager.alert("提示", "请选择正确的行数！", "info");  
	    return;  
	}
	var rows = $('#add_roleList_list_table').datagrid('getSelections');
	if(rows.length<1){
		$.messager.alert("提示", "请至少选择一行！", "info");  
	    return;  
	}
	var userIds = "";
	 //批量获取选中行的模板ID  
    for (i = 0; i < thisBean.length;i++) {
	      if (userIds =="") {
	    	  userIds = thisBean[i].id;  
	      } else {
	    	  userIds = thisBean[i].id +"," + userIds;
	      }      
	      
    }
	var names = "";
    var roleIds = "";  
	 //批量获取选中行的模板ID  
    for (i = 0; i < rows.length;i++) {
	      if (roleIds =="") {
	    	  roleIds = rows[i].id;  
	      	  names = rows[i].roleName;  
	      } else {
	    	  roleIds = rows[i].id +"," + roleIds;
	      	  names = rows[i].roleName +"," + names;
	      }
	      
    }
	$.messager.confirm('提示', '是否为选中的'+thisBean.length+'位用户添加<b>'+names+'</b>?', function (r) {
	      if (!r) {
	           return;  
	      }
	      $.ajax({
		      url:'${baseurl}DrivingSys/power/usersaddroles.action',  
		      type: "post",  
		      dataType:"json",
		      data:{"roleIds":roleIds,"userIds":userIds}, 
		      success: function(json) {
		    	  if(json.success <=0 ){
			        	$.messager.alert('提示',json.error,'warning');
		          }else if(json.success == 'success'){
			        	$.messager.show({
							title:'提示',
							msg:'添加成功!',
							timeout:3000,
							showType:'slide'
						});
			        	$('#add_RoleList_window_div').window('close');
		          }else{
		        	  $.messager.alert('提示',json.success,'warning');
		          }
		      }
		  });
		     
	});
}
//////////////////////////////////////////////////////////////

</script>
</html>